package com.foreknow.oop1;

public class Student {
  private int id;
  private String name;
  private int score;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getScore() {
    return score;
  }

  public void setScore(int score) {
    this.score = score;
  }

  //排序的
  public void getSort(Student[] stu){
      for(int j = 1;j<stu.length;j++){
        for(int i = 0;i<stu.length-j;i++){
          //根据student中的成绩进行比较
          if(stu[i].getScore()<stu[i+1].getScore()){
            Student temp = stu[i];
            stu[i] = stu[i+1];
            stu[i+1] = temp;
          }
        }
      }
    }

    public static void main(String[] args) {
      Student st1 = new Student();
      st1.setId(101);
      st1.setName("张三");
      st1.setScore(90);
      Student st2 = new Student();
      st2.setId(102);
      st2.setName("李四");
      st2.setScore(80);
      Student st3 = new Student();
      st3.setId(103);
      st3.setName("王五");
      st3.setScore(100);

      //将以上三个对象保存到student类型的数组中
      Student[] s = {st1,st2,st3};
      //调用排序的方法getSort（）参数需要传递一个类型？
      st1.getSort(s);
      //输出排序后的结果
      for(int i = 0;i<s.length;i++){
        System.out.println(s[i].getId()+"---"+s[i].getName()+"---"+s[i].getScore());
      }
    }
}
